<?php
require_once ('../../config/include_paths.php');
require_once('config.php');
require_once('functions.php');
require_once('dbconnect.php');	// database connect script.
if($_POST['id'] && $_POST['id'] != '') {$while = ' where id ='.$_POST['id'];}
$sql = "SELECT ID, title, concat(eventDate,' ',eventStartTime) as start, concat(eventEndDate,' ',eventEndTime) as end FROM events".$while;					
	$result =  mysql_query($sql) or die(mysql_error());
	$total = mysql_num_rows($result); 
	$rows = array();
	//start must be a date, end must test for 0000-00-000, and 00:01 and if either, ignore, if not, end 
	while($r = mysql_fetch_assoc($result)) {
		$r['start'] = date('Y-m-d H:i:s', strtotime($r['start']));
		$r['end'] = date('Y-m-d H:i:s', strtotime($r['end']));
		if ( $r['start'] < $r['end'] ) {
			$r['allDay'] = true;
		} else {
			$r['allDay'] = false;
			$r['end'] = '';
		}
		$r['url'] = 'eventsform.php?id='.$r['ID'];
    	$rows[] = $r;
	}

print json_encode($rows);
?>
